<!--
 @description 订单详情-商品信息
 @fileName GoodsList.vue
 @author zengqiongying
 @created 2021/07/10 13:36:28
-->
<template>
  <div>
    <div style="font-size:12px;color:red">预计出货时间为【目前无法满足】标识：目前该订单无法被最近批次出货的量满足，如果您着急可以找对应区域专员协调货源，如果您只想咨询出货进度，建议咨询商品管理部田英</div>
    <table-box
      ref="refTable"
      table-size="mini"
      :data="tableData"
      :table-config="tableConfig"
      :other-filters="otherFilters"
      :table-max-height="600"
      :table-sortable="true"
      show-index
    />
  </div>
</template>

<script>
import tabMixin from './mixin'
import { parseTime } from '@/utils'
import { fetchOrderDeliveryShip } from '@/api/mscInfo'
export default {
  name: 'OrderDetailGoods',
  mixins: [tabMixin],
  data() {
    return {
      tableData: [],
      otherFilters: [], // 表格额外查询条件
      otherRaws: {},
      tableConfig: {
        // interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/orderSku/page`,
        interfacePath: '',
        // hideSearchBar: true,
        hideFuncBar: true,
        tabIndex: 21,
        buttonGroupCode: 'detail_goods',
        pageSize: 50,
        // sort: 'soTime', // 开单时间
        // order: 'desc',
        setting: [
          {
            prop: 'ecSkuCode',
            label: '商品编码',
            minWidth: 200
          },
          {
            prop: 'ecSkuName',
            label: '商品名称',
            minWidth: 150
          },
          {
            prop: 'shipmentTime',
            label: '预计出货时间',
            minWidth: 150,
            render: (_h, { shipmentTime }) => {
              if (shipmentTime) {
                // 缺货
                if (shipmentTime === '目前无法满足') {
                // 缺货无分配
                  return <span style='color:red'>目前无法满足</span>
                } else if (shipmentTime === '不缺货') {
                  // 不缺货
                  return <span style='color:#3DC094'>不缺货</span>
                }
                return <span>{{ shipmentTime }}</span>
              }
              /* // 不缺货
              return <span style='color:#3DC094'>不缺货</span> */
              return <span>未知</span>
            }
          },
          {
            prop: 'buyQuantity',
            label: '购买数量',
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'closeQuantity',
            label: '售中关闭量',
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'returnQuantity',
            label: '售后关闭量',
            minWidth: 100,
            align: 'center'
          },
          {
            prop: 'price',
            label: '吊牌价',
            minWidth: 100
          },
          {
            prop: 'discountFee',
            label: '优惠价',
            minWidth: 100
          },
          {
            prop: 'adjustFee',
            label: '手工调整价格',
            minWidth: 120
          },
          {
            prop: 'receivablePrice',
            label: '成交单价',
            minWidth: 100
          },
          {
            prop: 'receivableFee',
            label: '成交金额',
            minWidth: 100
          },
          {
            prop: 'closedFee',
            label: '关闭金额',
            minWidth: 100
          },
          {
            prop: 'linkFee',
            label: '关联补差金额',
            minWidth: 120
          },
          {
            prop: 'alreadyUseFee',
            label: '已使用金额(补差)',
            minWidth: 150
          },
          {
            prop: 'isGift',
            label: '是否赠品',
            minWidth: 100,
            formatData: ({ isGift }) => {
              return isGift ? '是' : '否'
            }
          },
          {
            prop: 'giftSource',
            label: '赠品来源',
            minWidth: 150
          },
          {
            prop: 'giftTypeName',
            label: '赠品类型名称',
            minWidth: 150
          },
          {
            prop: 'giftRemark',
            label: '赠品备注',
            minWidth: 150
          },
          {
            prop: 'sendState',
            label: '发货状态',
            minWidth: 120,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'eco',
              dictTypeCode: 'SEND_STATUS'
            }
          },
          {
            prop: 'returnState',
            label: '关闭状态',
            minWidth: 120,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'eco',
              dictTypeCode: 'RETURN_STATUS'
            }
          },
          {
            prop: 'returnFeeState',
            label: '退款状态',
            minWidth: 120,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'eco',
              dictTypeCode: 'RETURN_FEE_STATUS'
            }
          },
          {
            prop: 'skuPlatformCode',
            label: '平台商品编码',
            minWidth: 150
          },
          {
            prop: 'sosonid',
            label: '子订单号',
            minWidth: 150
          },
          {
            prop: 'saleRefundApplyQuantity',
            label: '退款申请数量(售中)',
            minWidth: 150
          },
          {
            prop: 'saleRefundApplyFee',
            label: '退款申请金额(售中)',
            minWidth: 150
          },
          {
            prop: 'saleSettleShouldFee',
            label: '应结算金额(售中)',
            minWidth: 150
          },
          {
            prop: 'saleSettleShouldPrice',
            label: '应结算单价(售中)',
            minWidth: 150
          },
          {
            prop: 'saleSettleOverFee',
            label: '已结算金额(售中)',
            minWidth: 150
          },
          {
            prop: 'afterSaleRefundApplyQuantity',
            label: '退款申请数量(售后)',
            minWidth: 150
          },
          {
            prop: 'afterSaleRefundApplyFee',
            label: '退款申请金额(售后)',
            minWidth: 150
          },
          {
            prop: 'afterSaleSettleOverFee',
            label: '已结算金额(售后)',
            minWidth: 150
          },
          {
            prop: 'afterSaleSettleOverFee',
            label: '应结-已结(售中)',
            minWidth: 150,
            formatData: ({ saleSettleShouldFee, saleSettleOverFee }) => {
              return Number(saleSettleShouldFee || 0) - Number(saleSettleOverFee || 0)
            }
          },
          {
            prop: 'adjustOverQuantity',
            label: '核算量',
            minWidth: 120
          },
          {
            prop: 'settleOverQuantity',
            label: '结算量',
            minWidth: 120
          },
          {
            prop: 'rowAdjustState',
            label: '核算状态',
            minWidth: 120,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'eco',
              dictTypeCode: 'ADJUST_STATUS'
            }
          },
          {
            prop: 'rowSettleState',
            label: '结算状态',
            minWidth: 120,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'eco',
              dictTypeCode: 'SETTLE_STATUS'
            }
          },

          {
            prop: 'purTime',
            label: '采购时间',
            minWidth: 150,
            formatData: ({ purTime }) => {
              return parseTime(purTime)
            }
          },
          {
            prop: 'soTime',
            label: '开单时间',
            minWidth: 150,
            formatData: ({ soTime }) => {
              return parseTime(soTime)
            }
          },
          {
            prop: 'soAuditTime',
            label: '销售审核时间',
            minWidth: 150,
            formatData: ({ soAuditTime }) => {
              return parseTime(soAuditTime)
            }
          },
          {
            prop: 'withcarTime',
            label: '配车时间',
            minWidth: 150,
            formatData: ({ withcarTime }) => {
              return parseTime(withcarTime)
            }
          },
          {
            prop: 'transportTime',
            label: '发货时间', // 发货时间 = 启运时间
            minWidth: 150,
            formatData: ({ transportTime }) => {
              return parseTime(transportTime)
            }
          },
          {
            prop: 'signTime',
            label: '签收时间',
            minWidth: 150,
            formatData: ({ signTime }) => {
              return parseTime(signTime)
            }
          },
          {
            prop: 'storePlanTime',
            label: '排工时间',
            minWidth: 150,
            formatData: ({ storePlanTime }) => {
              return parseTime(storePlanTime)
            }
          },
          {
            prop: 'storeSendTime',
            label: '出库时间',
            minWidth: 150,
            formatData: ({ storeSendTime }) => {
              return parseTime(storeSendTime)
            }
          },
          {
            prop: 'completionTime',
            label: '完工时间',
            minWidth: 150,
            formatData: ({ completionTime }) => {
              return parseTime(completionTime)
            }
          },
          {
            prop: 'storeComfirmTime',
            label: '确认时间',
            minWidth: 150,
            formatData: ({ storeComfirmTime }) => {
              return parseTime(storeComfirmTime)
            }
          }
        ],
        btnList: []
      }
    }
  },
  computed: {

  },
  created() {
    /* this.otherFilters = [
      { id: 'orderId', property: 'orderId', operator: '=', value: this.orderId }
    ] */
  },
  methods: {
    initData() {
      this.tableData = (this.orderData && this.orderData.skuList) || []
      this.getShipmentTime()
      /* this.otherFilters = [
        { id: 'orderId', property: 'orderId', operator: '=', value: this.orderId }
      ]
      this.$nextTick(() => {
        this.$refs.refTable.initTableData()
      })*/
    },
    settingTable() {
      this.$refs.refTable.getMore('setting')
    },
    // 查询所有商品的预计出货时间
    async getShipmentTime() {
      const orderNo = this.orderData.ecCode
      let shipList = []
      await fetchOrderDeliveryShip(orderNo).then(res => {
        shipList = res.data || []
      })
      this.tableData.forEach(item => {
        const ecSkuCode = item.ecSkuCode
        const tmp = shipList.find(v => v.skuCode === ecSkuCode)
        if (tmp && tmp.shipmentTime) {
          item.shipmentTime = tmp.shipmentTime
        }
      })
    }
  }
}

</script>
<style lang='scss' scoped>
</style>
